package com.example.demo.config;
/* @Author      zouzh
 * @PackageName interceptor-demo
 * @Package     com.example.demo.config
 * @Date        2023/8/25 17:59
 */

import com.example.demo.common.ResultJAjax;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(NullPointerException.class)
    public ResultJAjax doNullPointerException(NullPointerException e){
        ResultJAjax resultJAjax = new ResultJAjax();
        resultJAjax.setCode(-1);
        resultJAjax.setMsg("空指针异常 " + e.getMessage());
        resultJAjax.setData(null);
        return resultJAjax;
    }

    @ExceptionHandler(Exception.class)
    public ResultJAjax doException(Exception e){
        ResultJAjax resultJAjax = new ResultJAjax();
        resultJAjax.setCode(-1);
        resultJAjax.setMsg("异常" + e.getMessage());
        resultJAjax.setData(null);
        return resultJAjax;
    }
}
